package com.itheima.d8_BSpro;

import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * B/S架构：简易版
 */
public class Server {
    public static void main(String[] args) throws Exception {
        System.out.println("---------服务器启动成功----------");
        //1.创建服务端对象 并指定端口
        ServerSocket ss = new ServerSocket(9191);
        //创建一个线程池
        ThreadPoolExecutor pool = new ThreadPoolExecutor(
                16,
                16,
                0,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(8),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy()
        );
        while (true) {
            //2.监听客户端
            Socket socket = ss.accept();
            System.out.println("一个网页客户端连接成功...");
            //3.创建一个线程
            pool.submit(new MyRunnable(socket));
        }
    }

}
